package com.example.zhu.controller;

import com.example.zhu.dto.ActivityDTO;
import com.example.zhu.entity.Activity;
import com.example.zhu.result.Result;
import com.example.zhu.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 查询活动列表
     * @return
     */
    @GetMapping("/getAll")
    public Result<List<Activity>> getAll(){
        List<Activity> list = activityService.selectAll();
        return Result.success(list);
    }

    /**
     * 获取当前的活动信息
     * @return
     */
    @GetMapping("/getEditInfo")
    public Result<Activity> getEditInfo(Integer id){
        Activity activity = activityService.getEditInfo(id);
        return Result.success(activity);
    }


    @PostMapping("/activate")
    public Result activate(@RequestBody ActivityDTO activite){
        log.info("{}",activite.getArea(),activite.getId());
        activityService.activate(activite.getArea(),activite.getId());
        return Result.success();
    }

    @PutMapping("/updateEditInfo")
    public Result updateEditInfo(@RequestBody Activity activity){

        return activityService.update(activity);
    }


}
